package edu.wpi.cs509.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import edu.wpi.cs509.common.exceptions.ServerUnreachable;
import edu.wpi.cs509.ui.A__MainStrategoClient;

/**
 * The action handler for login button on login screen
 * 
 * @author jprocess
 *
 */
public class LoginButtonAction implements ActionListener {
	private A__MainStrategoClient a__MainStrategoClient;
	private LoginScreenPanel loginPanel;
	
	/**
	 * Constructor for the action listener
	 * @param a__MainStrategoClient
	 */
	public LoginButtonAction(A__MainStrategoClient a__MainStrategoClient, LoginScreenPanel loginPanel) {
		this.a__MainStrategoClient = a__MainStrategoClient;
		this.loginPanel = loginPanel;
	}

	/**
	 * Handler for the action event
	 */
	@Override
	public void actionPerformed(ActionEvent ae) {
		
		String username = loginPanel.getUserName();
		String password = loginPanel.getPassword();
		String host = loginPanel.getHost();
		
		try {
			System.out.println("UI ---->  Login request made ----->");
			a__MainStrategoClient.getClientLogic().login(username, password, host);
		} catch (ServerUnreachable e) {
			// TODO Auto-generated catch block
			Dialog.displayConnectionLostDialog();
			e.printStackTrace();
		}
	}
}
